import {BasicColumn, FormSchema} from '/@/components/Table';
import {render} from '/@/utils/common/renderUtils';
import {listArticleGroup} from '../group/articleGroup.api';

export const columns: BasicColumn[] = [
  {
    title: '标题',
    width: 160,
    dataIndex: 'title',
  },
  {
    title: '所属分类',
    dataIndex: 'groupName',
    width: 100
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 60,
    customRender: ({text}) => {
      const color = text== '2' ? 'red': text == '1' ? 'green':'gray';
      return  render.renderTag(render.renderDict(text, 'article_status'),color)
    }
  },
  {
    title: '排序',
    width: 50,
    dataIndex: 'sortNo',
  },
  {
    title: '创建者',
    width: 100,
    dataIndex: 'createdBy',
  },
  {
    title: '创建时间',
    width: 160,
    dataIndex: 'createdAt',
  },
  {
    title: '更新时间',
    width: 160,
    dataIndex: 'updatedAt',
  }
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'title',
    label: '标题',
    component: 'Input',
  }
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'id',
    component: 'Input',
    show:false
  },
  {
    label: '文章组',
    field: 'groupId',
    component: 'ApiSelect',
    componentProps: {
      optionFilterProp: "label",
      labelField: 'name',
      valueField: 'id',
      showSearch: true,
      api: listArticleGroup,
    },
    colProps: {
      // span: '24',
      // style: {
      //   width: '30%'
      // }
    },
  },
  {
    field: 'title',
    label: '标题',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入标题',
    }
  },
  {
    field: 'remark',
    label: '摘要',
    component: 'InputTextArea'
  },
  {
    field: 'content',
    label: '内容',
    component: 'MyRichTextEditor',
  },
  {
    field: 'visitVirtual',
    label: '虚拟访问量',
    component: 'InputNumber',
    componentProps: {
      size: 'middle',
      style: {
        width: '20%'
      }
    }
  },
  {
    field: 'sortNo',
    label: '排序',
    component: 'InputNumber',
    componentProps: {
      size: 'middle',
      style: {
        width: '20%'
      }
    }
  },
  {
    field: 'status',
    label: '状态',
    required: true,
    component: 'JDictSelectTag',
    defaultValue:'1',
    componentProps: {
      type:'radio',
      dictCode:'article_status',
    },
  },
];

